package task1205.Demo.Demo3;

import task1205.Demo.Demo2.Demo1;
import task1205.Demo.Demo4.CallService;
import task1205.Demo.Demo4.NetService;
import task1205.Demo.Demo4.SendService;

public class SuperPackage extends SercicePackage implements CallService , SendService, NetService {
   private int talkTime;
   private int smsCount;
   private int flow;

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }
    public SuperPackage() {
        this.talkTime  = 200;
        this.smsCount = 50;
        this.flow = 1*1024;
        this.price = 78.0;
    }

    @Override
    public void ShowInfo() {
        System.out.println("超人套餐：通话时间为："+this.talkTime+"分钟/月，短信条数为："+this.smsCount+"条/月，上网流量为"+this.flow/1024+"GB/月");
    }

    @Override
    public int call(int minCount, Demo2 demo2) throws Exception {
        int temp = minCount;
        for (int i = 0; i < minCount; i++) {
            if (this.talkTime-demo2.getRealTalkTime()>=1){
                demo2.setRealTalkTime(demo2.getRealTalkTime()+1);
            }else if (demo2.getMoney()>=0.2){
                demo2.setRealTalkTime(demo2.getRealTalkTime()+1);
                demo2.setMoney(Demo1.sub(demo2.getMoney(),0.2));
                demo2.setConsumAmount(demo2.getConsumAmount()+0.2);
            }else {
                temp = i;
                throw new Exception("本次已通话"+i+"分钟，您的余额不足，请充值后在使用！");
            }
        }
        return temp;
    }

    @Override
    public int netPlay(int flow, Demo2 demo2) throws Exception {
        int temp = flow;
        for (int i = 0; i < flow; i++) {
            if (this.flow-demo2.getRealFlow()>=1){
                demo2.setRealFlow(demo2.getRealFlow()+1);
            }else if (demo2.getMoney() >= 0.1){
                demo2.setRealFlow(demo2.getRealFlow()+1);
                demo2.setMoney(Demo1.sub(demo2.getMoney(),0.1));
                demo2.setConsumAmount(demo2.getConsumAmount() + 0.1);
            }else {
                temp = i;
                throw new Exception("本次已使用流量"+i+"MB,您的余额不足，请充值后在使用！");
            }
        }
        return temp;
    }

    @Override
    public int sendMessage(int smsCount, Demo2 demo2) throws Exception {
        int temp = smsCount;
        for (int i = 0; i < smsCount; i++) {
            if (this.smsCount - demo2.getRealSMSCount()>=1){
                demo2.setRealSMSCount(demo2.getRealSMSCount()+1);
            }else if (demo2.getMoney()>= 0.1){
                demo2.setRealSMSCount(demo2.getRealSMSCount()+1);
                demo2.setMoney(Demo1.sub(demo2.getMoney(),0.1));
                demo2.setConsumAmount(demo2.getConsumAmount()+0.1);
            }else {
                temp = i;
                throw new Exception("本次已发送短信"+i+"条，您的余额不足，请充值后在时使用");
            }
        }
        return temp;
    }
}
